import json
import os
import numpy as n
from machine import *
from blender import *
import stats

STORE = "/netflix/characteristics/"

stat_data = stats.Stats(tr, stats.STORE)
stat_data.read_data()

class User_Avg_Char(Characteristic):
  min = 1.
  max = 5.
  name = "user_average"
  def get_char(self, uid, mid):
    return stat_data.basic_user[int(uid)][0]

class Movie_Avg_Char(Characteristic):
  min = 1.
  max = 5.
  name = "movie_average"
  def get_char(self, uid, mid):
    return stat_data.basic_movie[int(mid)][0]

class User_StdDev_Char(Characteristic):
  min = 0.
  max = 2.
  name = "user_stddev"
  def get_char(self, uid, mid):
    return stat_data.basic_user[int(uid)][1]

class Movie_StdDev_Char(Characteristic):
  min = 0.
  max = 2.
  name = "movie_stddev"
  def get_char(self, uid, mid):
    return stat_data.basic_movie[int(mid)][1]

class User_Erratic_Char(Characteristic):
  min = 0.
  max = 4.
  name = "user_erratic"
  def get_char(self, uid, mid):
    return stat_data.adv_user[int(uid)][1]
    
class Movie_Erratic_Char(Characteristic):
  min = 0.
  max = 4.
  name = "movie_erratic"
  def get_char(self, uid, mid):
    return stat_data.adv_movie[int(mid)][1]

class User_Ratings_Char(Characteristic):
  min = 0.
  max = 1000.
  name = "user_ratings"
  def get_char(self, uid, mid):
    return min(1000, len(tr.user(uid)))

class Movie_Ratings_Char(Characteristic):
  min = 0.
  max = 10000.
  name = "movie_ratings"
  def get_char(self, uid, mid):
    return min(10000, len(tr.movie(mid)))

characteristics = [ User_Avg_Char(),
                    Movie_Avg_Char(),
                    User_StdDev_Char(),
                    Movie_StdDev_Char(),
                    User_Erratic_Char(),
                    Movie_Erratic_Char(),
                    User_Ratings_Char(),
                    Movie_Ratings_Char(),
                  ]
  
    
    